package com.qf.web.controller;

import com.qf.pojo.Stu;
import com.qf.service.StuService;
import com.qf.service.impl.StuServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * projectName:huyi
 * author:jww
 * time:2024/5/2 13:47
 * description:
 */
@WebServlet("/update")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String id=request.getParameter("id");
        String stuname =request.getParameter("stuname ");
        String stuno =request.getParameter("stuno ");
        String pwd =request.getParameter("pwd ");
        String idcard =request.getParameter("idcard ");
        String startdate =request.getParameter("startdate ");
        String status =request.getParameter("status ");
        try {
            StuService stuService=new StuServiceImpl();
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
            System.out.println(sdf.parse(startdate));
            Stu stu=new Stu(Integer.parseInt(id),stuname,stuno,pwd,idcard,sdf.parse(startdate),Integer.parseInt(status));
            stuService.modify(stu);
            request.setAttribute("sub", "修改成功");
            request.getRequestDispatcher("successful.jsp").forward(request,response);
        } catch (ParseException e) {
            e.printStackTrace();
            request.setAttribute("msg", "更新学生失败"+e.getMessage());
            request.getRequestDispatcher("message.jsp").forward(request,response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}


